#include <utility>
#include <algorithm>

#ifndef _CUSTOM_VECTOR_H
#define _CUSTOM_VECTOR_H

using namespace std;

template<typename T>
	class CustomVector
	{
	public:
		CustomVector(size_t size = 0): actual(size), reserved(size)
		{
			data = new T[reserved];
		}

		CustomVector(const CustomVector & v): data(new T[v.actual]), actual(v.actual), reserved(v.reserved)
		{
			for(size_t i = 0; i < actual; i++)
			{
				data[i] = v.data[i];
			}
		}

		~CustomVector()
		{
			delete[] data;
		}

		CustomVector<T>& operator = (const CustomVector & cvector)
		{
			CustomVector tmp(cvector);
			Swap(tmp);
			return *this;
		}

		void Swap(CustomVector & cvector)
		{
			swap(cvector.data, data);
			swap(cvector.actual, actual);
			swap(cvector.reserved, reserved);
		}

		T& Get(size_t index)
		{
			return data[index];
		}

		const T& Get(size_t index) const
		{
			return data[index];
		}

		void Set(size_t index, const T& element)
		{
			data[index] = element;
		}

		size_t GetSize() const
		{
			return actual;
		}

		void PushBack(const T& element)
		{
			if(actual >= reserved)
			{
				T * next = new T[reserved = reserved > 0 ? reserved * MULTIPLY : 1];
				for(size_t i = 0; i < actual; i++)
				{
					next[i] = data[i];
				}

				delete[] data;
				data = next;
			}

			data[actual++] = element;
		}
	private:
		T * data;
		size_t actual;
		size_t reserved;
		static const size_t MULTIPLY = 2;
	};

#endif
